package com.dcivision.framework.taglib.channel.event;

import java.sql.Connection;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.taglib.channel.AjaxPageContext;

public abstract class AbstractAjaxAction {
  
  protected AjaxPageContext pageContext = null;
  public abstract Object execute()throws ApplicationException;
  protected SessionContainer getSessionContainer() throws ApplicationException{
    SessionContainer ctx = (SessionContainer)pageContext.getSession().getAttribute(GlobalConstant.SESSION_CONTAINER_KEY);
    if(ctx==null)
      throw new ApplicationException("SessionContainer is null");
    return(ctx);
  }
  
  protected Connection getConnection() throws ApplicationException{
    Connection   conn = (Connection)pageContext.getRequest().getAttribute(GlobalConstant.DB_KEY); 
    if(conn==null)
      throw new ApplicationException("Connection is null");
    return conn; 
  }
  
  public String init(AjaxPageContext pageContext){
    this.pageContext = pageContext;
    if(this.pageContext==null)
      return "error";
    return "success";
  }
  
  public void release(){
    pageContext = null;
  }
}
